#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const ll N = 3e5 + 10, INF = 0x3f3f3f3f;

ll n, q, L, R;
ll a[N], s[N], g[N], z[N], h[N];

ll f(ll x) { return x * (x + 1) / 2; }

ll P1(ll L, ll R)
{
    ll len = R - L + 1;
    return len * g[R] - (z[R - 1] - z[L - 2]);
}

ll P2(ll L, ll R)
{
    return R * (g[R - 1] - g[L - 2]) - (h[R - 1] - h[L - 2]);
}

void solve()
{
    cin >> n >> q;
    for (ll i = 1;i <= n;i++) {
        cin >> a[i];
        s[i] = s[i - 1] + a[i];
        g[i] = g[i - 1] + s[i];
        z[i] = z[i - 1] + g[i];
    }

    for (ll i = 1;i <= n;i++) {
        h[i] = h[i - 1] + i * s[i];
    }

    while (q--) {
        cin >> L >> R;
        cout << P1(L, R) - P2(L, R) << '\n';
    }
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    //cin>>T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}